package com.atguigu.day07.HomeWork;

import java.util.Scanner;

/**
 * @version 1.0
 * @Author 马冰
 * @Date 2024/11/6 19:42
 * @注释
 */

public class HomeWork2 {
    //判断是否是闰年
    public boolean isLeapYear(int year) {
        if ((year > 0) && (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)) {
            return true;
        }
        return false;
    }

    public String monthName(int month) {
        String monthName = "";
        switch (month) {
            case 1:
                monthName = "January";
                break;
            case 2:
                monthName = "February";
                break;
            case 3:
                monthName = "March";
                break;
            case 4:
                monthName = "April";
                break;
            case 5:
                monthName = "May";
                break;
            case 6:
                monthName = "June";
                break;
            case 7:
                monthName = "July";
                break;
            case 8:
                monthName = "August";
                break;
            case 9:
                monthName = "September";
                break;
            case 10:
                monthName = "October";
                break;
            case 11:
                monthName = "November";
                break;
            case 12:
                monthName = "December";
                break;
        }
        return monthName;
    }

    public int totalDaysOfMonth(int year, int month) {
        switch (month) {
            case 1, 3, 5, 7, 8, 10, 12:
                return 31;
            case 4, 6, 9, 11:
                return 30;
            case 2:
                if ((year > 0) && (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)) {
                    return 29;
                } else {
                    return 28;
                }
            default:
                return 0;
        }
    }

    public int totalDaysOfYear(int year) {
        if ((year > 0) && (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)) {
            return 366;
        } else {
            return 365;
        }
    }

    public int daysOfTheYear(int year, int month, int day) {
        int days = 0;
        switch (month) {
            case 12:
                days += 30;
            case 11:
                days += 31;
            case 10:
                days += 30;
            case 9:
                days += 31;
            case 8:
                days += 31;
            case 7:
                days += 30;
            case 6:
                days += 31;
            case 5:
                days += 30;
            case 4:
                days += 31;
            case 3:
                days += 28;
                if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
                    days++;
                }
            case 2:
                days += 31;
        }
        days += day;
        return days;
    }
}

class HomeWork2Test{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入年份：");
        int year = sc.nextInt();
        System.out.println("请输入月份：");
        int month = sc.nextInt();
        System.out.println("请输入日期：");
        int day = sc.nextInt();

        HomeWork2 h2 = new HomeWork2();
        System.out.println("今年是否为闰年：" + h2.isLeapYear(year));
        System.out.println(month + "月的英语单词是：" + h2.monthName(month));
        System.out.println(year + "年" + month + "月共有" + h2.totalDaysOfMonth(year, month) + "天");
        System.out.println(year + "年共有" + h2.totalDaysOfYear(year) + "天");
        System.out.println("这一天是" + year + "年的第" + h2.daysOfTheYear(year, month, day));
    }
}